package cn.zymall.goods.controller;

import cn.zymall.common.controller.crud.BaseController;
import cn.zymall.common.model.SpuAttr;
import cn.zymall.goods.service.SpuAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lxh
 * @Description 商品属性控制层
 * @date 2020/8/18 9:54
 * @Classname KindsController
 **/
@RestController
@RequestMapping("/spuAttr")
public class SpuAttrController extends BaseController<SpuAttrService, SpuAttr> {
	@Autowired
	private SpuAttrService spuAttrService;

	/**
	 * 根据商品类型id查询商品属性
	 * @param id
	 * @return
	 */
	@GetMapping("/getById/{id}")
	public List<SpuAttr> getById(@PathVariable(name = "id") Integer id){
		return spuAttrService.findById(id);
	}


	/**
	 * 添加商品属性
	 * @param spuAttr
	 */
	@PostMapping("/add")
	public void add(SpuAttr spuAttr) {
		System.out.println(spuAttr);
		spuAttrService.add(spuAttr);
	}

	/**
	 * 修改商品属性
	 * @param spuAttr
	 */
	@PostMapping("/amend")
	public void amend(SpuAttr spuAttr) {
		spuAttrService.amend(spuAttr);
	}


	/**
	 * 删除商品属性
	 * @param spuAttr
	 */
	@PostMapping("/del")
	public void del(SpuAttr spuAttr) {
		System.out.println(spuAttr);
		spuAttrService.del(spuAttr);
	}


	/**
	 * 根据商品分类查找未禁用的商品属性
	 * @param id
	 */
	@GetMapping("/findAllById/{id}")
	public List<SpuAttr> findAllById(@PathVariable(name = "id") Integer id){
		System.out.println(id);
		return spuAttrService.findAllById(id);
	}

	/**
	 * 根据属性id查找属性
	 * @param id
	 * @return
	 */
	@GetMapping("/findSpuAttrById/{id}")
	public SpuAttr findSpuAttrById(@PathVariable(name = "id") Integer id){
		return spuAttrService.findSpuAttrById(id);
	}

	/**
	 * 添加基本属性
	 * @param spuAttr
	 * @return
	 */
	@PostMapping("/addBaseAttr")
	public SpuAttr addBaseAttr(SpuAttr spuAttr) {
		return spuAttrService.addBaseAttr(spuAttr);
	}


	/**
	 * 根据id删除属性
	 * @param id
	 */
	@DeleteMapping("/delAttr/{id}")
	public void delAttr(@PathVariable(name = "id") Integer id){
		spuAttrService.delAttr(id);
	}




	/**
	 * 根据商品分类id查找属性
	 * @param id
	 * @return
	 */
	@GetMapping("/findByKindsId")
	public List<SpuAttr> findByKindsId(Integer kindsId,Integer spuId){
		return spuAttrService.findByKindsId(kindsId,spuId);
	}

}
